import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


/**
 * @author： pang-yun
 * @date： 2022-02-10 18:01
 * Description:
 */

public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        //元素个数
        int count= s.nextInt();
        Integer[] arr = new Integer[count];

        //数组元素
        for(int i=0; i<count; i++){
            int number= s.nextInt();
            arr[i]=number;
        }

        //升序降序
        int flag =s.nextInt( );
        if(flag==0){
            Arrays.sort(arr, new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return o1 - o2;
                }
            });


        }
        if(flag==1){
            Arrays.sort(arr, new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    return o2 - o1;
                }
            });


        }
        Arrays.stream(arr).forEach(a-> System.out.print(a+" "));
    }

}